/// ---------------------------------------------
///
/// 汪定新
///
/// ---------------------------------------------

var FormulaData = "";

$(document).ready(function () {
    //函数参数名发生变化时，函数结果的参数名也相应变化
    var lastParmName = "";
    setTimeout(function () {
        DataValueEvent();
    }, 200);
    $("#btnSetFormula").click(function () { //设置表达式
        FormulaData = $("#rsReturn").val();
        document.getElementById("EditUIWindow").src = "../EHR/hrSalaryFormula.aspx?flag=1&r=" + Math.random();
        setTimeout(function () {
            $("#dialogArea").fbmodal({
                title: "公式设置",
                cancel: "退出",
                okay: "确定",
                modal: true,
                okaybutton: true,
                cancelbutton: true,
                buttons: true,
                opacity: 0.0,
                fadeout: true,
                overlayclose: true,
                modaltop: "15%",
                modalwidth: "450",
                modalheight: "270"
            }, _callBack);
        }, 100);
    });
});

var fnCustomeRowAddEvent = function () {
    setTimeout(function () {
        DataValueEvent();
    }, 50);
}

var DataValueEvent = function () {
    $("input[name=DataValue]").unbind();
    $("input[name=DataValue]").click(function () {
        var obj = $(this);
        lastParmName = $(this).val();
        FormulaData = lastParmName;
        document.getElementById("EditUIWindow").src = "../EHR/hrSalaryFormula.aspx?flag=2&r=" + Math.random();
        setTimeout(function () {
            $("#dialogArea").fbmodal({
                title: "公式设置",
                cancel: "退出",
                okay: "确定",
                modal: true,
                okaybutton: true,
                cancelbutton: true,
                buttons: true,
                opacity: 0.0,
                fadeout: true,
                overlayclose: true,
                modaltop: "15%",
                modalwidth: "450",
                modalheight: "270"
            }, function () {
                obj.val(FormulaData);
            });
        }, 100);
    });
    $("input[name=DataValue]").change(function () {
        if (lastParmName == "") return;
        var paramName = $(this).val();
        var rs = $("#rsReturn").val();
        rs = rs.replace(new RegExp(lastParmName, "g"), paramName);
        $("#rsReturn").val(rs);
        //表格中参数数据变更
        for (var i = 0; i < _DataTable.Rows.length; i++) {
            var row = _DataTable.Rows[i];
            if (row.Parameter == lastParmName) {
                row.Parameter = paramName;
            }
        }
    });
}

//用于对话框"确定"按钮的回调
var _callBack = function (status) {
    if (status == 1) {
        $("#rsReturn").val(FormulaData);
    }
}

var fnCustomAdd = function () {
    const_EditEntity = "salSalaryFunction";
    var pagetitle = "新增薪资函数";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity));
    parent.NeedRefreshPage = this;
}

var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "salSalaryFunction";
    var pagetitle = "修改薪资函数—" + record.getData("Name");
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}

//数据验证
var fnCheckData = function () {
    if ($("#Name").val() == "" || $("#Name").val() == null) {
        return "函数名称不能为空！";
    }
    if ($("#Functions").val() == "" || $("#Functions").val() == null) {
        return "函数称不能为空！";
    }
}
